package com.wzcl.app.model.common;


import org.springframework.security.core.AuthenticationException;

import java.io.PrintWriter;
import java.io.StringWriter;

public class BusinessException extends AuthenticationException {

    private static final long serialVersionUID = 1L;

    private Integer code;

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    /**
     * 模板快速生成
     * @param codeMsg
     */
    public BusinessException(CodeMsg codeMsg) {
        super(codeMsg.getMsg());
        this.code = codeMsg.getCode();
    }

    /**
     * 替换模板中的信息
     * @param codeMsg
     * @param message
     */
    public BusinessException(CodeMsg codeMsg, String message) {
        super(message);
        this.code = codeMsg.getCode();
    }

    /**
     * 自定义异常
     * @param code
     * @param message
     */
    public BusinessException(Integer code, String message) {
        super(message);
        this.code = code;
    }

    public static String collectExceptionStackMsg(Exception e){
        StringWriter sw = new StringWriter();
        e.printStackTrace(new PrintWriter(sw, true));
        String strs = sw.toString();
        return strs;
    }
}
